package com.bysc.cmsservice.controller;


import com.bysc.baseservice.handler.BaiYunException;
import com.bysc.cmsservice.entity.GuideType;
import com.bysc.cmsservice.service.GuideTypeService;
import com.bysc.commonutils.ResultCode;
import com.bysc.commonutils.Results;
import com.bysc.commonutils.constant.MessageConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 附近攻略分类 前端控制器
 * </p>
 *
 * @author kkk
 * @since 2025-03-06
 */
@RestController
@Api(tags = "附近攻略分类管理")
@RequestMapping("/cmsservice/guide-type")
public class GuideTypeController {

    @Autowired
    private GuideTypeService guideTypeService;

    /*
    * 新增攻略分类
    * */
    @ApiOperation(value = "新增攻略分类")
    @PostMapping("/addGuideType")
    public Results addGuideType(@RequestBody GuideType guideType){
        try {
            guideTypeService.save(guideType);
            return Results.ok().message(MessageConstant.ADD_GUIDETYPE_SUCCESS);
        } catch (Exception e) {
            throw new BaiYunException(ResultCode.ERROR, MessageConstant.ADD_GUIDETYPE_FAIL);
        }
    }

    /*
    * 根据id修改攻略分类
    * */
    @ApiOperation(value = "根据id修改攻略分类")
    @PostMapping("/updateGuideTypeById/{id}")
    public Results updateGuideTypeById(@RequestBody GuideType guideType){
        try {
            guideTypeService.updateById(guideType);
            return Results.ok().message(MessageConstant.UPDATE_GUIDETYPE_SUCCESS);
        }
        catch (Exception e){
            throw new BaiYunException(ResultCode.ERROR, MessageConstant.UPDATE_GUIDETYPE_FAIL);
        }
    }

    /*
    * 根据id查询攻略分类
    * */
    @ApiOperation(value = "根据id查询攻略分类")
    @PostMapping("/getGuideTypeById/{id}")
    public Results getGuideTypeById(@PathVariable String id){
        try {
            GuideType Type = guideTypeService.getById(id);
            return Results.ok().data("guideType",Type).message(MessageConstant.GET_GUIDETYPE_SUCCESS);
        }
        catch (Exception e) {
            throw new BaiYunException(ResultCode.ERROR, MessageConstant.GET_GUIDETYPE_FAIL);
        }
    }

    /*
    * 根据id删除攻略分类
    * */
    @ApiOperation(value = "根据id删除攻略分类")
    @DeleteMapping("/deleteGuideTypeById/{id}")
    public Results deleteGuideTypeById(@PathVariable String id){
        try {
            guideTypeService.removeById(id);
            return Results.ok().message(MessageConstant.DELETE_GUIDETYPE_SUCCESS);
        }
        catch (Exception e){
            throw new BaiYunException(ResultCode.ERROR, MessageConstant.DELETE_GUIDETYPE_FAIL);
        }
    }

    /*
    * 修改攻略分类
    * */
    @ApiOperation(value = "修改攻略分类")
    @PostMapping("/updateGuideType")
    public Results updateGuideType(@RequestBody GuideType guideType){
        try {
            guideTypeService.updateById(guideType);
            return Results.ok().message(MessageConstant.UPDATE_GUIDETYPE_SUCCESS);
        }
        catch (Exception e){
            throw new BaiYunException(ResultCode.ERROR, MessageConstant.UPDATE_GUIDETYPE_FAIL);
        }
    }

    /*
    * 查询所有攻略分类
    * */
    @ApiOperation(value = "查询所有攻略分类")
    @PostMapping("/getAllGuideType")
    public Results getAllGuideType(){
        try {
            return Results.ok().data("guideTypeList",guideTypeService.list(null)).message(MessageConstant.GET_GUIDETYPE_SUCCESS);
        }
        catch (Exception e){
            throw new BaiYunException(ResultCode.ERROR, MessageConstant.GET_GUIDETYPE_FAIL);
        }
    }

    /*
    * 根据typeId查询排序
    * */
    @ApiOperation(value = "根据typeId查询排序")
    @PostMapping("/getSortByTypeId/{typeId}")
    public Results getSortByTypeId(@PathVariable String typeId){
        try {
            return Results.ok().data("sort",guideTypeService.getById(typeId)).message(MessageConstant.GET_GUIDETYPE_SUCCESS);
        }
        catch (Exception e){
            throw new BaiYunException(ResultCode.ERROR, MessageConstant.GET_GUIDETYPE_FAIL);
        }
    }




}

